package com.itheima.service;

import com.alibaba.dubbo.config.annotation.Service;
import com.github.pagehelper.Page;
import com.github.pagehelper.PageHelper;
import com.itheima.dao.MemberDao;
import com.itheima.entity.Result;
import com.itheima.entity.PageResult;
import com.itheima.pojo.CheckGroup;
import com.itheima.pojo.Member;
import com.itheima.pojo.Report;

import javax.annotation.Resource;
import java.util.Date;
import java.util.List;

/**
 * @author M.F.S
 */
@Service(version = "1.0.0", interfaceClass = MemberService.class)
public class MemberServiceImpl implements MemberService {


    @Resource
    private MemberDao memberDao;


    @Override
    public Result findByFileId(Long fileId) {
        Member member = memberDao.findByFileId(fileId);
        if(member == null){
            return  new Result(false, "没用该档案");
        }else {
            return new Result(true, "查询成功", member);
        }
    }

    /**
     * 根据手机号查找会员
     *
     * @param telephone 手机号
     * @return 会员实例
     */
    @Override
    public Member findByPhoneNumber(String telephone) {
        return memberDao.findByPhoneNumber(telephone);
    }

    /**
     * 会员分页查询
     *
     * @param currentPage
     * @param pageSize
     * @param queryString
     * @return
     */
    @Override
    public PageResult findPage(Integer currentPage, Integer pageSize, String queryString) {
        //开启分页查询
        PageHelper.startPage(currentPage, pageSize);
        //调用dao层查询语句
        Page<Member> page = memberDao.findPage(queryString);
        List<Member> result = page.getResult();
        //封装分页查询结果对象
        return new PageResult(page.getTotal(), result);
    }

    /**
     * 根据id查询会员档案
     *
     * @param id
     * @return
     */
    @Override
    public Member findById(int id) {
        return memberDao.findById(id);
    }

    /**
     * 编辑会员档案
     *
     * @param member
     */
    @Override
    public void update(Member member) {
        memberDao.update(member);
    }

    /**
     * 新增会员档案信息
     *
     * @param member 会员实例
     */
    @Override
    public void add(Member member) {
        memberDao.add(member);
    }

    /**
     * 删除会员档案信息
     *
     * @param id
     */
    @Override
    public void delete(int id) {
        memberDao.delete(id);
    }

    /**
     * 查询会员信息(会员数据回显)
     *
     * @return
     */
    @Override
    public List<Member> findMember() {
        List<Member> list = memberDao.findMember();
        return list;
    }

    /**
     * 回显会员信息
     * @param id
     * @return
     */
    @Override
    public Member findByIdInfo(Integer id) {
        return  memberDao.findByIdInfo(id);
    }

}
